package com.test.dao.role;

import com.test.dao.BaseDao;
import com.test.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoTmpl implements RoleDao{
    /**
     * 获取角色列表
     * @param connection
     * @return
     * @throws SQLException
     */
    public List<Role> getRoleList(Connection connection) throws SQLException {
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        List<Role> roleList = new ArrayList<Role>();
        if(connection != null){
            StringBuffer sql = new StringBuffer();
            sql.append("select * from smbms_role");
            List<Object> list = new ArrayList<Object>();
            Object[] params = list.toArray();
            System.out.println(sql);
            // 获取结果集
            resultSet = BaseDao.execute(connection, sql.toString(), params, resultSet, preparedStatement);
            while (resultSet.next()){
                Role _role = new Role();
                _role.setId(resultSet.getInt("id"));
                _role.setRoleCode(resultSet.getString("roleCode"));
                _role.setRoleName(resultSet.getString("roleName"));
                roleList.add(_role);
            }
            // 释放资源
            BaseDao.closeResource(null,resultSet,preparedStatement);
        }
        return roleList;
    }
}
